package littlewhisker.components.ui.dial {
	import flash.events.MouseEvent;
	import flash.display.Sprite;

	/**
	 * @author Philip
	 */

	public class RotaryPotentiometer extends AbstractDial {
		
		public function get percent() : Number {
			var percent:Number = (asset.rotation+(Math.abs(minLimit)))/(Math.abs(minLimit)+maxLimit);
			return percent;
		}
		
		public function set percent(percent:Number):void{
			destination = ((Math.abs(minLimit)+maxLimit)*percent)+minLimit;	
			rotate();
		}		
				
		public function RotaryPotentiometer(asset:Sprite):void {
			if(asset){
				this.asset = asset;
			}
		}
		
		override protected function onMove(event:MouseEvent) : void {
			var newX:Number = asset.stage.mouseX - prevX;
			var newY:Number =  prevY-asset.stage.mouseY;
			var distance:Number = (newX+newY)/2;
			destination = destination + distance;
			if(destination>maxLimit){
				destination = maxLimit;	
			}
			if(destination<minLimit){
				destination = minLimit;
			}
			rotate();
		}
	}
}
